package com.rt.sms.utils;


import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.HttpServletRequest;


/**
 * Token校验类
 **/
public class SmsTokenUtil {
    public static boolean checkToken(HttpServletRequest request){
        boolean flag = false;

        String appid = request.getParameter("appid");
        String shijian = request.getParameter("shijian");
        String user_id = request.getParameter("user_id");
        String token = request.getParameter("token");

        if(StringUtils.isBlank(appid)|| StringUtils.isBlank(shijian)
                ||StringUtils.isBlank(shijian)||StringUtils.isBlank(token)){
            return flag;
        }

        StringBuffer buffer = new StringBuffer("");
        buffer.append("appid=" + appid);
        buffer.append("&user_id=" + user_id);
        buffer.append("&shijian=" + shijian);
        String mytoken=MD5.GetMD5Code(buffer.toString());
        if(token.equals(mytoken)){
            flag = true;
        }
        return flag;
    }
}